package org.john.common.util;

import org.apache.commons.lang3.ArrayUtils;

import java.util.List;

public class Detect {

    public static boolean isNegative(short value) {
        return value < 0;
    }

    public static boolean isNegative(int value) {
        return value < 0;
    }

    public static boolean isNegative(Byte value) {
        return value != null && value < 0;
    }

    public static boolean isNegative(long value) {
        return value < 0;
    }

    public static boolean isNegative(float value) {
        return value < 0;
    }

    public static boolean isNegative(double value) {
        return value < 0;
    }

    public static boolean isPositive(long value) {
        return value > 0;
    }

    public static boolean isPositive(float value) {
        return value > 0;
    }

    public static boolean isPositive(short value) {
        return value > 0;
    }

    public static boolean isPositive(Byte value) {
        return value != null && value > 0;
    }

    public static boolean isPositive(int value) {
        return value > 0;
    }

    public static boolean isPositive(double value) {
        return value > 0;
    }

    public static boolean containsAll(long[] values, long[] subValues) {
        if (ArrayUtils.isEmpty(values) && ArrayUtils.isEmpty(subValues)) {
            return true;
        }

        if (ArrayUtils.isEmpty(values)) {
            return false;
        }

        if (ArrayUtils.isEmpty(subValues)) {
            return true;
        }

        for (long subValue : subValues) {
            if (!ArrayUtils.contains(values, subValue)) {
                return false;
            }
        }

        return true;
    }

    public static <E> boolean contains(List<E> list, E one) {
        return list.indexOf(one) != -1;
    }

    public static boolean onlyOne(List<?> list) {
        return !list.isEmpty() && list.size() == 1;
    }

    public static boolean between(long value, long floor, long ceil) {
        return value >= floor && value <= ceil;
    }

}
